package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.util.Utils;

public class IF extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 3)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    Object localObject3 = paramArrayOfObject[2];
    if (((localObject1 instanceof Boolean) && (((Boolean)localObject1).booleanValue())) || (Boolean.valueOf(Utils.objectToString(localObject1)).booleanValue()))
      return localObject2;
    return localObject3;
  }

  public Function.Type getType()
  {
    return Function.LOGIC;
  }

  public String getCN()
  {
    return "IF(boolean,number1/string1,number2/string2):判断函数,boolean为true时返回第二个参数,为false时返回第三个。\nboolean: 用于判断的布尔值,true或者false。\nnumber1/string1: 第一个参数，如果boolean为ture,返回这个值。\nnumber2/string2: 第二个参数，如果boolean为false,返回这个值。\n示例:\nIF(true,2,8)等于2\nIF(false,\"first\",\"second\")等于second\nIF(true,\"first\",7)等于first";
  }

  public String getEN()
  {
    return "IF(boolean,number1/string1,number2/string2): Returns number1/striing1 if boolean you specify evaluates to TRUE and number2/string2 if it evaluates to FALSE.\nboolean is any value or expression that can be evaluated to TRUE or FALSE.\nnumber1/string1 is the value that is returned if boolean is TRUE.\nnumber2/string2 is the value that is returned if boolean is FALSE.\n\nExample:\n   IF(true,2,8) = 2\n   IF(false,\"first\",\"second\") = \"second\"\n   IF(true,\"first\",7) = \"first\"";
  }
}